// JavaScript Document
function onSubmitForm(formName,url)
{ 
	var theForm = document.getElementById(formName);
	theForm.action = url;
	multipleSelectOnSubmit();
	theForm.submit();	
	
	//javascript:$('#fileUploadgrowl').fileUploadStart();
	return true;
	
	
}

function checkCheckBox(){
	var theForm = document.appForm;
	if (theForm.elements[i].name=='cid[]')
	{
        theForm.elements[i].checked = checked;
        if(theForm.elements[i].checked = true){
        	window.alert(this.value);
        }
    }
}

var checked=false;
function checkedAll() {
    var theForm = document.appForm;
    if (checked == false)
    {
    	checked = true;
    	//theForm.checkValue.value = theForm.elements.length;
    }
    else
    {
    	checked = false;
    	//theForm.checkValue.value = 0;
    }
    
    var countCheckBox = 0;
    for (i=0; i<theForm.elements.length; i++) {
        if (theForm.elements[i].name=='cid[]'){
            theForm.elements[i].checked = checked;
            countCheckBox++;
        }
    }
    
    if (checked == true)
    {
    	theForm.checkValue.value = countCheckBox;
    }
    else
    {    	
    	theForm.checkValue.value = 0;
    }
}

$(document).ready( function(){
	$(".hori").mouseover( function() { $(this).addClass("over") });
	$(".hori").mouseout( function() { $(this).removeClass("over") });
	$(".hori").click( function(){ 
		$(this).find(".check").each(function(){ this.checked = !this.checked;});
	});

	$("#status").change(function(){		
		status=this.value;
		$.cookie("status",status,{ expires: 7 });
		document.location.reload();
	});						   
	$("#status").val($.cookie("status"));
	
	$("#featured").change(function(){		
		featured=this.value;
		$.cookie("featured",featured,{ expires: 7 });
		document.location.reload();
	});						   
	$("#featured").val($.cookie("featured"));
	
	$("#special").change(function(){		
		special=this.value;
		$.cookie("special",special,{ expires: 7 });
		document.location.reload();
	});						   
	$("#special").val($.cookie("special"));
	
	$("#cat_tour").change(function(){		
		cat_tour=this.value;
		$.cookie("cat_tour",cat_tour,{ expires: 7 });
		document.location.reload();
	});						   
	$("#cat_tour").val($.cookie("cat_tour"));
	
	$("#cat_cruise").change(function(){		
		cat_cruise=this.value;
		$.cookie("cat_cruise",cat_cruise,{ expires: 7 });
		document.location.reload();
	});						   
	$("#cat_cruise").val($.cookie("cat_cruise"));	
	
	$("#destination").change(function(){		
		destination=this.value;
		$.cookie("destination",destination,{ expires: 7 });
		document.location.reload();
	});						   
	$("#destination").val($.cookie("destination"));	
	
	$("#subdes").change(function(){		
		subdes=this.value;
		$.cookie("subdes",subdes,{ expires: 7 });
		document.location.reload();
	});						   
	$("#subdes").val($.cookie("subdes"));	
	
	$("[name=khoa]").change(function(){		
		status=this.value;
		$.cookie("khoa",status,{ expires: 7 });
		document.location.reload();
	});						   
	$("#khoa").val($.cookie("khoa"));	
	
	$("#countries").change(function(){		
		countries=this.value;
		$.cookie("countries",countries,{ expires: 7 });
		$.cookie("destination", null);
		$.cookie("cat_tour", null);
		$.cookie("menus", null);
		$.cookie("cat_cruise", null);
		$.cookie("cat_hotel", null);
		document.location.reload();
	});						   
	$("#countries").val($.cookie("countries"));	
	
	$("#menus").change(function(){		
		menus=this.value;
		$.cookie("menus",menus,{ expires: 7 });
		document.location.reload();
	});						   
	$("#menus").val($.cookie("menus"));	
	
	$("#position").change(function(){		
		position=this.value;
		$.cookie("position",position,{ expires: 7 });
		document.location.reload();
	});						   
	$("#position").val($.cookie("position"));	
	
	$("#tours").change(function(){		
		tours=this.value;
		$.cookie("tours",tours,{ expires: 7 });
		document.location.reload();
	});						   
	$("#tours").val($.cookie("tours"));
	
	$("#cruises").change(function(){		
		cruises=this.value;
		$.cookie("cruises",cruises,{ expires: 7 });
		document.location.reload();
	});						   
	$("#cruises").val($.cookie("cruises"));
	
	$("#tourcruises").change(function(){		
		tourcruises=this.value;
		$.cookie("tourcruises",tourcruises,{ expires: 7 });
		document.location.reload();
	});						   
	$("#tourcruises").val($.cookie("tourcruises"));

   

	$("#hotels").change(function(){		
		hotels=this.value;
		$.cookie("hotels",hotels,{ expires: 7 });
		document.location.reload();
	});						   
	$("#hotels").val($.cookie("hotels"));

    $("#cat_hotel").change(function(){		
		cat_hotel=this.value;
		$.cookie("cat_hotel",cat_hotel,{ expires: 7 });
		document.location.reload();
	});						   
	$("#cat_hotel").val($.cookie("cat_hotel"));

	
	$("#secnews").change(function(){	
		secnews=this.value;
		$.cookie("secnews",secnews,{ expires: 7 });
		$.cookie("catnews", null);
		document.location.reload();
	});						   
	$("#secnews").val($.cookie("secnews"));

	$("#catnews").change(function(){		
		catnews=this.value;
		$.cookie("catnews",catnews,{ expires: 7 });
		$.cookie("tours", null);
		document.location.reload();
	});						   
	$("#catnews").val($.cookie("catnews"));
	
	$( "#start_date" ).datepicker({
		numberOfMonths: 1,  dateFormat: 'yy/mm/dd',
	});
	$( "#finish_date" ).datepicker({
		numberOfMonths: 1,  dateFormat: 'yy/mm/dd',
	});
	
});


function BrowseServer( startupPath, functionData ){
	var finder = new CKFinder();
	finder.basePath = 'public/templates/admin/system/ckfinder/'; //Ä�Æ°á»�ng path nÆ¡i Ä‘áº·t ckfinder
	finder.startupPath = startupPath; //Ä�Æ°á»�ng path hiá»‡n sáºµn cho user chá»�n file
	finder.selectActionFunction = SetFileField; // hÃ m sáº½ Ä‘Æ°á»£c gá»�i khi 1 file Ä‘Æ°á»£c chá»�n
	finder.selectActionData = functionData; //id cá»§a text field cáº§n hiá»‡n Ä‘á»‹a chá»‰ hÃ¬nh
	//finder.selectThumbnailActionFunction = ShowThumbnails; //hÃ m sáº½ Ä‘Æ°á»£c gá»�i khi 1 file thumnail Ä‘Æ°á»£c chá»�n	
	finder.popup(); // Báº­t cá»­a sá»• CKFinder
} //BrowseServer

function SetFileField( fileUrl, data ){
	document.getElementById( data["selectActionData"] ).value = fileUrl;
}

function ShowThumbnails( fileUrl, data ){	
	var sFileName = this.getSelectedFile().name; // this = CKFinderAPI
	document.getElementById( 'thumbnails' ).innerHTML +=
	'<div class="thumb">' +
	'<img src="' + fileUrl + '" />' +
	'<div class="caption">' +
	'<a href="' + data["fileUrl"] + '" target="_blank">' + sFileName + '</a> (' + data["fileSize"] + 'KB)' +
	'</div>' +
	'</div>';
	document.getElementById( 'preview' ).style.display = "";
	return false; // náº¿u lÃ  true thÃ¬ ckfinder sáº½ tá»± Ä‘Ã³ng láº¡i khi 1 file thumnail Ä‘Æ°á»£c chá»�n
}



